<?php
    require_once 'connexion (2).php';
    
    
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <link rel="stylesheet" href="feuilledestyle.css">
        <link rel="stylesheet" href="menuHead/jquery.cleditor.css">
        <link href="menu2/styles.css" rel="stylesheet" type="text/css">
        <script type="text/javascript" src="ajax/detail.js"></script>
        <script type="text/javascript">
            function afficherStage()
            {
                //alert("rentre");
                    if (listeS.choix[0].checked) 
                        {
                            
                           document.listeS.unique.value='tout';
                        
                        }else if (listeS.choix[1].checked) 
                                { 
                                    document.listeS.unique.value='unique';
                                  
                                } 
            }
        </script>
    </head>
    <body vlink="blue">
        <div id="page">
        <?php include 'header.php';?>
        <div id="cadre">
            <?php include 'menu.php';?>
             <FORM style="float:left; margin-top: 20px; background-color: orange; "> <INPUT TYPE="button" VALUE="Retour" onClick="history.back()"> </FORM> 
            <div class="centre">
                <h3>Stages Proposés</h3>
                <?php
                    if(isset($_SESSION['mail']))
                    {
                        
                         $req_="select * from personne as p, maitrestage as m where m.IDMAITRESTAGE=p.IDPERSONNE and MAILPERSONNE='".$_SESSION['mail']."'";
                            $resu_=$connexion->query($req_);
                            if ($re=$resu_->fetch(PDO::FETCH_ASSOC))
                            {
                                $idmaitre=$re["IDMAITRESTAGE"];
                            }
                        $typep=null;
                        if(isset($_GET['typep']))
                        {
                            $typep=$_GET['typep'];
                        }
                        if($typep=='eleve')
                        {
                            $req_rando="select * from stage s, entreprise e where s.IDENTREPRISE=e.IDENTREPRISE and ETATSTAGE='En Attente'";
                            $resu_ra=$connexion->query($req_rando);
                            while ($rep=$resu_ra->fetch(PDO::FETCH_ASSOC))
                            {
                                $id=$rep["IDSTAGE"];
                                $etatS=$rep["ETATSTAGE"];
                                $sujetS=$rep["SUJETSTAGE"];
                                $dateDS=$rep["DATEDEBUT"];
                                $dateFS=$rep["DATEFIN"];
                                $nomEn=$rep["NOMENTREPRISE"];
                                $adrE=$rep["ADRESSEENTREPRISE"];
                                $telE=$rep["TELENTREPRISE"];
                                $web=$rep["SITE"];
                                $adrEweb=$rep["MAILENTREPRISE"];

                                echo '<table id="listevS" class="petitformcom" align="center">
                                        <tr style="margin-left: auto; margin-right: auto;">
                                            <th>Etat du Stage</th>
                                            <th>Nom Entreprise</th>
                                            <th>Date Début du Stage</th>
                                            <th></th><th></th>
                                            <th>Date Fin du Stage</th>
                                        </tr>
                                        <tr style="margin-left: auto; margin-right: auto; color: slategray;">
                                            <td>'.$etatS.'</td>
                                            <td>'.$nomEn.'</td>
                                            <td>'.$dateDS.'</td>
                                            <td></td><td></td>
                                            <td>'.$dateFS.'</td>
                                        </tr>
                                        <tr style="margin-left: auto; margin-right: auto;">
                                            <th>Adresse Entreprise</th>
                                            <th>Téléphone Entreprise</th>
                                            <th>Adresse Web</th>
                                            <th></th><th></th>
                                            <th>Site Web</th>
                                        </tr>
                                        <tr style="margin-left: auto; margin-right: auto; color: slategray;">
                                            <td>'.$adrE.'</td>
                                            <td>'.$telE.'</td>
                                            <td><a href= "'.$adrEweb.'" target="_block" >'.$adrEweb.'</a></td>
                                            <td></td><td></td>
                                            <td><a href= "'.$web.'" target="_block" >'.$web.'</a></td>
                                        </tr>
                                    </table><br>
                                    ';
                            }
                        }
                        else if ($typep=='professeur')
                        {
                            $req_rando="select * from stage s, entreprise e where s.IDENTREPRISE=e.IDENTREPRISE and ETATSTAGE='En Attente'";
                            $resu_ra=$connexion->query($req_rando);
                            while ($rep=$resu_ra->fetch(PDO::FETCH_ASSOC))
                            {
                                $id=$rep["IDSTAGE"];
                                $etatS=$rep["ETATSTAGE"];
                                $sujetS=$rep["SUJETSTAGE"];
                                $dateDS=$rep["DATEDEBUT"];
                                $dateFS=$rep["DATEFIN"];
                                $nomEn=$rep["NOMENTREPRISE"];
                                $adrE=$rep["ADRESSEENTREPRISE"];
                                $telE=$rep["TELENTREPRISE"];
                                $web=$rep["SITE"];
                                $adrEweb=$rep["MAILENTREPRISE"];

                                echo '<table id="listevS" class="petitformcom" align="center">
                                        <tr style="margin-left: auto; margin-right: auto;">
                                            <th>Etat du Stage</th>
                                            <th>Nom Entreprise</th>
                                            <th>Date Début du Stage</th>
                                            <th></th><th></th>
                                            <th>Date Fin du Stage</th>
                                        </tr>
                                        <tr style="margin-left: auto; margin-right: auto; color: slategray;">
                                            <td>'.$etatS.'</td>
                                            <td>'.$nomEn.'</td>
                                            <td>'.$dateDS.'</td>
                                            <td></td><td></td>
                                            <td>'.$dateFS.'</td>
                                        </tr>
                                        <tr style="margin-left: auto; margin-right: auto;">
                                            <th>Adresse Entreprise</th>
                                            <th>Téléphone Entreprise</th>
                                            <th>Adresse Web</th>
                                            <th></th><th></th>
                                            <th>Site Web</th>
                                        </tr>
                                        <tr style="margin-left: auto; margin-right: auto; color: slategray;">
                                            <td>'.$adrE.'</td>
                                            <td>'.$telE.'</td>
                                            <td><a href= "'.$adrEweb.'" target="_block" >'.$adrEweb.'</a></td>
                                            <td></td><td></td>
                                            <td><a href= "'.$web.'" target="_block" >'.$web.'</a></td>
                                        </tr>
                                    </table><br>
                                    ';
                            }
                        }else if ($typep=='maitrestage')
                        {
                            
                            if(isset($_POST['choix'])&& $_POST['choix']=="tout")
                            {
                             $req_m="select * from personne as p, stage as s, maitrestage as m, entreprise as ent where s.IDENTREPRISE=ent.IDENTREPRISE and m.IDENTREPRISE=ent.IDENTREPRISE and m.IDMAITRESTAGE=p.IDPERSONNE and MAILPERSONNE='".$_SESSION['mail']."'";
                               echo '<form name="listeS" method="POST" onsubmit="afficherStage()" >
                                 <input type="hidden"  name="unique" />
                                 <table id="listevS" class="petitformcom" align="center" border="0">
                                        <tr style="margin-left: auto; margin-right: auto; background-color:orange;">
                                            <th><input type="radio" value="tout" name="choix" onclick="afficherStage()" checked="checked">Tous les Stages</th>
                                            <th><input type="radio" value="unique" name="choix" onclick="afficherStage()">Que mes Stages</th>

                                        <td><input type="submit"/></td>
                                        </tr>
                                </table>
                                </form>';    
                                
                                 

                            }else {
                              $req_m="select * from stage as s, maitrestage as m, encadre as e where m.IDMAITRESTAGE=e.IDMAITRESTAGE and s.IDSTAGE=e.IDSTAGE and m.IDMAITRESTAGE=".$idmaitre;
                             echo '<form name="listeS" method="POST" onsubmit="afficherStage()" >
                                 <input type="hidden"  name="unique" />
                                 <table id="listevS" class="petitformcom" align="center" border="0">
                                        <tr style="margin-left: auto; margin-right: auto; background-color:orange;">
                                            <th><input type="radio" value="tout" name="choix" onclick="afficherStage()">Tous les Stages</th>
                                            <th><input type="radio" value="unique" name="choix" onclick="afficherStage()" checked="checked">Que mes Stages</th>
                                       
                                        <td><input type="submit"/></td>
                                        </tr>
                                </table>
                                </form>';
                                 
                             }
                                    
                            
                           
                            // var_dump($req_m);
                            $resu_m=$connexion->query($req_m);
                            while ($rep=$resu_m->fetch(PDO::FETCH_ASSOC))
                            {
                                $id=$rep["IDSTAGE"];
                                $etatS=$rep["ETATSTAGE"];
                                $sujetS=$rep["SUJETSTAGE"];
                                $dateDS=$rep["DATEDEBUT"];
                                $dateFS=$rep["DATEFIN"];
                                

                                echo '<table id="listevS" class="petitformcom" align="center">
                                        <tr style="margin-left: auto; margin-right: auto;">
                                            <th>Etat du Stage</th>
                                            <th>Date Début du Stage</th>
                                            <th></th><th></th>
                                            <th>Date Fin du Stage</th>
                                        </tr>
                                        <tr style="margin-left: auto; margin-right: auto; color: slategray;">
                                            <td>'.$etatS.'</td>
                                            <td>'.$dateDS.'</td>
                                            <td></td><td></td>
                                            <td>'.$dateFS.'</td>
                                        </tr>
                                        <tr style="margin-left: auto; margin-right: auto;">
                                            <th>Sujet</th>
                                            
                                          <td><textarea cols="20" rows="4" readonly="readonly">'.$sujetS.'</textarea></td>
                                           
                                            <th></th> <td></td>
                                            <td><a href= "ajouterOffre.php?action=modifier&idstage='.$id.'" >modifier</a><br><br>';
                                            if(($etatS=="En attente")||($etatS=="Annulé"))
                                            {
                                                ?> 
                                                <a href= "ajouterOffre.php?action=supprimer&idstage=<?php echo $id;?>" onclick="return (confirm('Voulez-vous vraiment supprimer cet offre de stage ?'));" >supprimer</a>
                                            <?php }
                                             echo '</td>
                                        </tr>
                                    </table><br>
                                    ';
                            }
                        }
                    }
                ?>
            </div>
             <FORM style="float:left; margin-top: -20px; background-color: orange; "> <INPUT TYPE="button" VALUE="Retour" onClick="history.back()"> </FORM> 
            <?php require_once 'pied.php';?>
        </div>
        </div>
    </body>
</html>